<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of BOnlineAppointment
 *
 * @author I062261
 */
class BWeEvent extends BApp {

    protected $eventTypeList = array();

    public function run($data = NULL) {
        parent::run($data);
    }

    public function runSetupEvent($data = NULL) {
        $sender = Blyn::app()->getUIManager()->getSenderControl();
        $updateControl = Blyn::app()->getUIManager()->getUpdateControl();
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $processPostObj = new BAProcessData();
        $postData = $processPostObj->parsedModelData();
        $activeLink = Blyn::app()->getUIManager()->getActiveLink();

        //add default view 
        if ($sender instanceof BUIOperation) {
            $screen->addRenderView('eventList', 'event_list_admin');
        }

        //add default view 
        if ($sender->isAjaxLinkClicked('showAdmin')) {
            $screen->addRenderView('eventList', 'event_list_admin');
        }

        //show add event
        if ($sender->isAjaxLinkClicked('showAddEvent')) {
            $eventId = $activeLink->getLinkVariable('eventId');

//            if ($eventId == NULL || $eventId == 0)
//            {
//                //get user's tempary data
//                $eventTable = new BAEventSheet(Blyn::app()->getCurrentUser());
//                $userEvent = $eventTable->getList();
//                $eventId = $userEvent->getId();
//               
//            }


            $updateControl->addRenderView('showAddEvent', 'event_add', array('eventId' => $eventId));
        }
        if ($sender->isAjaxLinkClicked('modifyEvent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $updateControl->addRenderView('showAddEvent', 'event_add', array('eventId' => $eventId));
        }
        if ($sender->isAjaxLinkClicked('deleteEvent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
           
            $eventTable = new BAEventSheet();
            if (is_numeric($eventId) && $eventId > 0) {
                $event = $eventTable->getListById($eventId);
                    $event->getListNode()->status = -1;
                    $event->save();
                }
                  $updateControl->addRenderView('event_list_admin');
            }
          
        
        //save event
        if ($sender->isAjaxLinkClicked('saveEvent')) {
            $eventId = $activeLink->getLinkVariable('eventId');

            $eventTable = new BAEventSheet();
            if (is_numeric($eventId) && $eventId > 0) {
                $event = $eventTable->getListById($eventId);
                //must set, otherwise, can not show event list correctly
                $event->setOwner(Blyn::app()->getActiveSpace());
            } else {
                $event = $eventTable->getNewList();
            }

            $mediaList = $processPostObj->populateMediaListFromPostData($postData, 'event_info');

            $itemData = array();
            foreach ($mediaList as $media) {
                $name = $media->name;
                $value = $media->content;
                $itemData[$name] = $value;
            }


            //save to table
            $event->addItems($itemData);

            //show event list
            $updateControl->addRenderView('event_list_admin');
        }

        if ($sender->isAjaxLinkClicked('addEventAttribute')) {
            $eventId = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('eventId');
            $attributeId = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('attributeId');

            $eventTable = new BAEventSheet();
            $event = $eventTable->getListById($eventId);

            $attributeTable = new BASheet('eventAttribute', $event);

            if ($attributeId == NULL || $attributeId == 0) {
                $attribute = $attributeTable->getNewList();
            }

            if (is_numeric($attribute) && $attributeId > 0) {
                $attribute = $attributeTable->getListById($attributeId);
            }

            $mediaList = $processPostObj->populateMediaListFromPostData($postData, 'event_attribute');

            $items = array();
            foreach ($mediaList as $media) {
                $attribute->addItem($media->name, $media->content);
            }

            $updateControl->addRenderView('showAddEvent', 'event_add', array('eventId' => $eventId));
        }

        //admin event
        if ($sender->isAjaxLinkClicked('adminEvent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $eventTable = new BAEventSheet();
            $event = $eventTable->getListById($eventId);

            $adminView = 'event_admin';
            $adminViewItem = $event->getItem('adminView');
            if ($adminViewItem) {
                $adminView = $adminViewItem->getValue();
            }

            $updateControl->addRenderView('showAdminEvent', $adminView, array('eventId' => $eventId));
        }
    }

    public function runManageEvent($data = NULL) {
        $sender = Blyn::app()->getUIManager()->getSenderControl();
        $updateControl = Blyn::app()->getUIManager()->getUpdateControl();
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $processPostObj = new BAProcessData();
        $postData = $processPostObj->parsedModelData();
        $activeLink = Blyn::app()->getUIManager()->getActiveLink();

        //add default view 
        if ($sender instanceof BUIOperation) {
            $screen->addRenderView('manageEventList', 'event_list_manage');
        }
        //show manage list
        if ($sender->isAjaxLinkClicked('showManage')) {
            $updateControl->addRenderView('manageEventList', 'event_list_manage');
        }
        if ($sender->isAjaxLinkClicked('showTtrainList')) {
            
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showTtrainList', 'match_manage', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        //show manageEventContent
        if ($sender->isAjaxLinkClicked('showAddManageEventContent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'hamshun_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('showAddManageEventContentofClube')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'club_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('showAddManageEventContentofHonour')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');

            $updateControl->addRenderView('showManageEventContent', 'honour_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('showAddManageEventContentofNews')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'news_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('showAddManageEventContentofMatch')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'match_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        //delete manageEventContent
        if ($sender->isAjaxLinkClicked('deleteManageEventContent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $eventTable = new BAEventSheet();
            if (is_numeric($eventId) && $eventId > 0) {
                $event = $eventTable->getListById($eventId);
                $manageEventContentTable = new BAEventSheet($event);
                if (is_numeric($contentId) && $contentId > 0) {
                    $content = $manageEventContentTable->getListById($contentId);
                    $content->getListNode()->status = -1;
                    $content->save();
                }
            }
            $updateControl->addRenderView('showManageEvent', $manageView, array('eventId' => $eventId, 'manageView' => $manageView));
        }
        //modify manageEventContent
        if ($sender->isAjaxLinkClicked('modifyManageEventContentofClube')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'club_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('modifyManageEventContentofHonour')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'honour_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('modifyManageEventContentofNews')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'news_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('modifyManageEventContentofMatch')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'match_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }
        if ($sender->isAjaxLinkClicked('modifyManageEventContent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $manageView = $activeLink->getLinkVariable('manageView');
            $contentId = $activeLink->getLinkVariable('contentId');
            $updateControl->addRenderView('showManageEventContent', 'hamshun_manage_content', array('eventId' => $eventId, 'manageView' => $manageView, 'contentId' => $contentId));
        }

        //save manageEventContent
        if ($sender->isAjaxLinkClicked('saveManageEventContent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $contentId = $activeLink->getLinkVariable('contentId');
            $manageView = $activeLink->getLinkVariable('manageView');
//            $manageEventContentTable = new BAEventSheet('manageEventContent');
//            $content = $manageEventContentTable->getListById($eventId);
            $eventTable = new BAEventSheet();
            if (is_numeric($eventId) && $eventId > 0) {
                $event = $eventTable->getListById($eventId);
                $manageEventContentTable = new BAEventSheet($event);
                if (is_numeric($contentId) && $contentId > 0) {
                    $content = $manageEventContentTable->getListById($contentId);
                    $content->setOwner($event);
                } else {
                    $content = $manageEventContentTable->getNewList();
                }
                $mediaList = $processPostObj->populateMediaListFromPostData($postData, 'event_info');

                $itemData = array();
                foreach ($mediaList as $media) {
                    $name = $media->name;
                    $value = $media->content;
                    $itemData[$name] = $value;
                }
                $content->addItems($itemData);
            }
            $updateControl->addRenderView('showManageEvent', $manageView, array('eventId' => $eventId, 'manageView' => $manageView));
        }
        //show hamshun_manage
        if (!$sender instanceof BUIOperation && $sender->isAjaxLinkClicked('manageEvent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $eventTable = new BAEventSheet();
            $event = $eventTable->getListById($eventId);

            $manageView = 'event_manage';
            $manageViewItem = $event->getItem('manageView');
            if ($manageViewItem) {
                $manageView = $manageViewItem->getValue();
            }

            $updateControl->addRenderView('showManageEvent', $manageView, array('eventId' => $eventId, 'manageView' => $manageView));
        }
         if (!$sender instanceof BUIOperation && $sender->isAjaxLinkClicked('showJoinList')) {
            $eventId = $activeLink->getLinkVariable('eventId');
              $contentId = $activeLink->getLinkVariable('contentId');
            $manageView = $activeLink->getLinkVariable('manageView');

            $updateControl->addRenderView('showJoinList', 'match_manage_content_train', array('eventId' => $eventId,  'contentId' => $contentId, 'manageView' => $manageView));
        }
          if (!$sender instanceof BUIOperation && $sender->isAjaxLinkClicked('showJoinTeamList')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $contentId = $activeLink->getLinkVariable('contentId');
            $manageView = $activeLink->getLinkVariable('manageView');

            $updateControl->addRenderView('showJoinList', 'match_manage_content_train_team', array('eventId' => $eventId, 'contentId' => $contentId, 'manageView' => $manageView));
        }
    }

    public function runFollowEvent($data = NULL) {
        $sender = Blyn::app()->getUIManager()->getSenderControl();
        $updateControl = Blyn::app()->getUIManager()->getUpdateControl();
        $screen = Blyn::app()->getUIManager()->getCurrentScreen();
        $processPostObj = new BAProcessData();
        $postData = $processPostObj->parsedModelData();
        $wxMenu = new BUIWXMenu(Blyn::app()->getActiveOperation());
//        $followBookingPage = new BUIWXControl('BUIWXControl');
        $wxControl = new BUIWXControl();
        //hamshun index
        if ($sender->isAjaxLinkClicked('hamshun_index')) {
            $updateControl->addRenderView('hamshun_follow', 'hamshun_follow');
        }


        //add default view 
        if ($sender instanceof BUIOperation) {
            $screen->addRenderView('followEventList', 'event_list_follow');
        }
        if ($wxControl->isLinkClicked('hamshun_jqm')) {
            $screen = Blyn::app()->getUIManager()->getCurrentScreen();
            $wxControl = new BUIWXControl('page');
            $screen->addChildControl($wxControl);
            $wxControl->addRenderView('hamshun_index');
        }
        if ($wxControl->isLinkClicked('guanzhe_jqm')) {
            $screen = Blyn::app()->getUIManager()->getCurrentScreen();
            $wxControl = new BUIWXControl('page');
            $screen->addChildControl($wxControl);
            $wxControl->addRenderView('guanzhe_index');
        }
        if ($wxControl->isLinkClicked('guanzhe_jqm_2')) {
            $screen = Blyn::app()->getUIManager()->getCurrentScreen();
            $wxControl = new BUIWXControl('page');
            $screen->addChildControl($wxControl);
            $wxControl->addRenderView('guanzhe_index_2');
        }
        if ($sender->isAjaxLinkClicked('goIndex')) {//返回首页
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $updateControl->addRenderView('showView', $viewName, array());
        }

        if ($sender->isAjaxLinkClicked('introduce')) {//介绍页面
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $updateControl->addRenderView('showView', $viewName, array());
        }
        if ($sender->isAjaxLinkClicked('join')) {//训练报名
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $contentId=  Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('contentId');
            $updateControl->addRenderView('showView', $viewName, array( 
                'contentId' => $contentId,
                'infoId' => 0,
            ));
        }
            if ($sender->isAjaxLinkClicked('saveJoinEventContent')) {

            $eventTable1 = new BAEventSheet();
            $event1 = $eventTable1->getList(array('itemData' => array('name' => 'trainList')));
             
            $eventId = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('eventId');
            
            $contentId = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('contentId'); 
            $eventTable = new BAEventSheet($event1);
           
            if (is_numeric($eventId) && $eventId > 0) {
                $event = $eventTable->getListById($eventId);
                $manageEventContentTable = new BAEventSheet($event);
                if (is_numeric($contentId) && $contentId > 0) {
                    $content = $manageEventContentTable->getListById($contentId);
                    $content->setOwner($event);
                } else {
                    $content = $manageEventContentTable->getNewList();
                }
                
                $mediaList = $processPostObj->populateMediaListFromPostData($postData, 'event_info');

                $itemData = array();
                foreach ($mediaList as $media) {
                    $name = $media->name;
                    $value = $media->content;
                    $itemData[$name] = $value;
                }
                $content->addItems($itemData);
            }
              echo "<script>alert('报名成功');</script>";
            $updateControl->addRenderView('showView', 'guanzhe_index_2', array());
        }
                 if ($sender->isAjaxLinkClicked('saveJoinTeamEventContent')) {

            $eventTable1 = new BAEventSheet();
            $event1 = $eventTable1->getList(array('itemData' => array('name' => 'trainList')));

            $eventId = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('eventId');

            $contentId = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('contentId');
            $eventTable = new BAEventSheet($event1);

            if (is_numeric($eventId) && $eventId > 0) {
                $event = $eventTable->getListById($eventId);
                $manageEventContentTable = new BAEventSheet($event);
                if (is_numeric($contentId) && $contentId > 0) {
                    $content = $manageEventContentTable->getListById($contentId);
                    $content->setOwner($event);
                } else {
                    $content = $manageEventContentTable->getNewList();
                    $content->getListNode()->status = 1;
                    $content->save();
                }

                $mediaList = $processPostObj->populateMediaListFromPostData($postData, 'event_info');

                $itemData = array();
                foreach ($mediaList as $media) {
                    $name = $media->name;
                    $value = $media->content;
                    $itemData[$name] = $value;
                }
                $content->addItems($itemData);
            }
            echo "<script>alert('报名成功');</script>";
            $updateControl->addRenderView('showView', 'guanzhe_index_2', array());
        }
        if ($sender->isAjaxLinkClicked('clubArticle')) {//俱乐部详细内容
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $eventTable = new BAEventSheet();
            $event = $eventTable->getList(array('itemData' => array('name' => 'clubList')));
            $manageEventContentTable = new BAEventSheet($event);
            $eventList = $manageEventContentTable->getView();

            $updateControl->addRenderView('showView', $viewName, array('eventList' => $eventList));
        }
        //教练\学员 列表
        if ($sender->isAjaxLinkClicked('introduceList')) {
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
           // $listName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('listName');
            $eventTable = new BAEventSheet();
            if ($viewName == 'introduceStudent') {
                $event = $eventTable->getList(array('itemData' => array('name' => 'studentList')));
                $manageEventContentTable = new BAEventSheet($event);
                $eventList = $manageEventContentTable->getView();
            } else if ($viewName == 'introduceTeacher') {
                $event = $eventTable->getList(array('itemData' => array('name' => 'teacherList')));
                $manageEventContentTable = new BAEventSheet($event);
                $eventList = $manageEventContentTable->getView();
            }
            $updateControl->addRenderView('showView', 'introduceList', array('eventList' => $eventList, 'viewName' => $viewName));
        }

        if ($sender->isAjaxLinkClicked('introduceArticle')) { //教练\学员 详细内容
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $updateControl->addRenderView('showView', $viewName, array());
        }
        //荣誉墙
        if ($sender->isAjaxLinkClicked('honour')) {
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $eventTable = new BAEventSheet();

            $event = $eventTable->getList(array('itemData' => array('name' => 'resultList')));
            $manageEventContentTable = new BAEventSheet($event);
            $resultList = $manageEventContentTable->getView();

            $event = $eventTable->getList(array('itemData' => array('name' => 'brandList')));
            $manageEventContentTable = new BAEventSheet($event);
            $brandList = $manageEventContentTable->getView();

            $event = $eventTable->getList(array('itemData' => array('name' => 'mediumList')));
            $manageEventContentTable = new BAEventSheet($event);
            $mediumList = $manageEventContentTable->getView();

            $updateControl->addRenderView('showView', $viewName, array(
                'resultList' => $resultList,
                'brandList' => $brandList,
                'mediumList' => $mediumList
            ));
        }
        //赛事发布
        if ($sender->isAjaxLinkClicked('news')) {
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $eventTable = new BAEventSheet();

            $event = $eventTable->getList(array('itemData' => array('name' => 'newsList')));
            $newsEventContentTable = new BAEventSheet($event);
            $newsList = $newsEventContentTable->getView();

            $event = $eventTable->getList(array('itemData' => array('name' => 'trainList')));
            $trainEventContentTable = new BAEventSheet($event);
            $trainList = $trainEventContentTable->getView();

            $event = $eventTable->getList(array('itemData' => array('name' => 'gameList')));
            $gameEventContentTable = new BAEventSheet($event);
            $gameList = $gameEventContentTable->getView();

            
            $event = $eventTable->getList(array('itemData' => array('name' => 'activityList')));
            $activityEventContentTable = new BAEventSheet($event);
            $activityList = $activityEventContentTable->getView();


            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $updateControl->addRenderView('showView', $viewName, array(
                'newsList' => $newsList,
                'trainList' => $trainList,
                'gameList' => $gameList,
                'activityList' => $activityList
            ));
        }
        
        //赛事页面详情
        if ($sender->isAjaxLinkClicked('newsArticle'))
        {
            $viewName = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('viewName');
            $newsTitle = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('newsTitle');
             $author = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('author');
             $info = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('info');
              $image = Blyn::app()->getUIManager()->getActiveLink()->getLinkVariable('image');
              
            $updateControl->addRenderView('showView', $viewName,array(
                'newsTitle'=>$newsTitle,
                'author'=>$author,
                'info'=>$info,
                'image'=>$image
                ));
        }
        
        
        //follow event
        if (!$sender instanceof BUIOperation && $sender->isAjaxLinkClicked('manageEvent')) {
            $eventId = $activeLink->getLinkVariable('eventId');
            $eventTable = new BAEventSheet();
            $event = $eventTable->getListById($eventId);

            $followView = 'event_follow';
            $followViewItem = $event->getItem('followView');
            if ($followViewItem) {
                $followView = $followViewItem->getValue();
            }

            $updateControl->addRenderView('showFollowEvent', $followView, array('eventId' => $eventId));
        }
    }

    public function getEventTypeList($data = NULL) {
        $bAppComm = new BAppCommon();

        $typeList = $bAppComm->getEventTypeList($data);

        if ($typeList == NULL) {
            $bAppComm->addEventType(array(
                'wePage' => 'wePage',
                'wePoll' => 'wePoll'
            ));
            $typeList = $bAppComm->getEventTypeList();
        }

        return $typeList;
    }

    /**
     * **** to get menu of space, can do it like below:******
     * $spaceMenu = new BUIMenu($activeSpace);
     * $appNodes = $spaceMenu->getChildren();
     * foreach($appNodes as $appNode){
     * $opNodes = $appNode->getChildren();
     * }
     * foreach($opNodes as $opNode){
     * $firstLevelMenuList = $opNode->getChildren();
     * $secondLevelMenu = $firstMenu->getChildren();
     * *****to handle menu, should like below***********
     * in runXXXOperation function, do blow to catch click of menu
     * if($sender->isMenuClicked($nameOfMenu){ //name can be nested
     * ....
     * }
     * @param type $menuData, format like array('name1'=>'value1','name2.name3'=>'value2'...
     * support nested menu
     * @param type $operation
     */
//    public function addOperationMenuToSpace($menuData, $operation = NULL) {
//        if ($operation == NULL)
//            $operation = Blyn::app()->getActiveOperation();
//        if (is_string($operation)) {
//            $oName = $operation;
//            $operation = Blyn::app()->getActiveApp()->getOperation($oName);
//        }
//
//        if ($operation instanceof BOperation) {
//            $appId = $operation->getApp()->getId();
////            $spMenu = new BUIMenu(Blyn::app()->getActiveSpace());
//            $spMenu = new BUIMenu(Blyn::app()->getActiveApp());
////            $appNode = $spMenu->addChild(array('name' => 'app_' . $appId, 'appId' => $appId));
//            $opNode = $spMenu->addChild(array('name' => 'op_' . $operation->getId(), 'appId' => $appId));
//            if (is_array($menuData)) {
//                foreach ($menuData as $name => $value) {
//                    $opNode->addChild(array('name' => $name, 'value' => $value));
//                }
//            }
//        }
//    }
}

?>
